home *** CD-ROM | disk | FTP | other *** search
/ Power Tools 1993 November - Disc 2 / Power Tools Plus (Disc 2 of 2)(November 1993)(HP).iso / hotlines / gsyhl / hpuxcomp.txt < prev    next >
Text File  |  1993-03-29  |  14KB  |  259 lines

  1.                 The Power of HP-UX Compiler Optimizations
  2.  
  3.  
  4. 1.0     Abstract
  5.  
  6. Any code compiled without optimization may be missing a great opportunity for
  7. performance improvement. A study of the effect of compiler optimization on the
  8. benchmarks in the SPEC CINT92 suite shows that, compared to unoptimized code,
  9. there is an easy 15 to 25% gain available and performance gains of 25 to 60%
  10. may be available to those who utilize more of the optimizer. Note that the
  11. benchmarks studied are not highly-tunable or easily-optimized floating-point
  12. benchmarks, these are C language, integer benchmarks which are much like many
  13. of the HP-UX applications.
  14.  
  15. 2.0     Executive Summary
  16.  
  17. While the exact effect varied from benchmark code to benchmark code, just
  18. turning on Level One (+O1), which should be safe on virtually all code,
  19. generally gained about 20% faster execution. Using Level Two (-O or +O2),
  20. the standard level of optimization, generally gained up to 50% performance
  21. increase. And if every feature available was utilized the gains were usually
  22. in the 40 - 60% range, with one benchmark that did better than a two-fold
  23. increase in performance.
  24.  
  25. It is well worth investigating the use of optimization for any code compiled
  26. on a HP-UX 9.0 or later system, even if optimization was not considered impor-
  27. tant for earlier releases. The 9.0 and later compilers trade-off simpler
  28. code generation for faster compile and link times if no optimization is
  29. specified. Thus with 9.0, if no optimization is used, it is very likely that
  30. there will be a 10% performance drop even before any kernel or system impacts
  31. are considered.
  32.  
  33. 3.0     Observations
  34.  
  35. The use of just Level One optimization is virtually a free 20% performance
  36. gain over not using any optimization. Level One optimization just applies the
  37. simple, in- line, statement-level, safe optimizations which can be used by
  38. just about any piece of code. Still, these easy optimizations provided between
  39. 15 and 25% improvement in most cases in the CINT92 suite.
  40.  
  41. Level Two optimization, the standard level of optimization (-O), offers another
  42. performance gain ranging from 5 - 10% percent for "branchy" system-type code to
  43. 20 - 30% for more "loopy" analytic-style code. There are benefits for almost
  44. all programs in Level Two optimizations, including a nice reduction in the
  45. overhead of procedure calling, but the big gains will be in those pieces of
  46. code which spend a fair amount of time in a few key loops. For the one case,
  47. out of the six in CINT92, that best exemplifies this "loopy" behavior, Level
  48. Two brought almost a two-fold performance improvement over Level One.
  49.  
  50. At this point, there was only a small gain by attempting Level Three
  51. optimizations on the examples in the CINT92 suite. There seems to be less
  52. advantage in the ad- vanced optimization methods for this kind of system
  53. application C code. However, Level Three did have a significant impact in the
  54. results of the CFP92, the floating- point suite, which has benchmarks which
  55. are much more analytic in nature.
  56.  
  57. However, there is another optimization that is well worth considering. The use
  58. of archive libraries, rather than the default of shared libraries can make a
  59. noticeable difference. Even code which rarely made any library calls had a
  60. detectable, 1 - 2%, difference when linked shared. But code which makes a high
  61. number of calls to library routines may see as much as 20% improvement with the
  62. use of archived executables rather than dynamically linked shared libraries.
  63.  
  64. 4.0     Results
  65.  
  66. 4.1     Result Summary
  67.  
  68. Across this variety of benchmarks, the HP-UX 9.0 compilers average better than
  69. 20% improvement on Level One (+O1) optimization alone. Turning on Level Two
  70. generates an average improvement of almost 60%. The use of archived libraries
  71. rather than shared libraries offers an additional 8% performance. This gives a
  72. 68% total improvements over the defaults, all of which is available without
  73. touching any source code.
  74.  
  75.  
  76.         Table 1: Relative Speedups with Various Levels of Optimization
  77.  
  78.                 SPECint92       none    +O1     +O2     +O3     +O3archived
  79.                 008             1.00    1.26    1.59    1.59    1.66
  80.                 022             1.00    1.25    1.52    1.54    1.57
  81.                 023             1.00    1.38    2.62    2.62    2.77
  82.                 026             1.00    1.18    1.40    1.42    1.46
  83.                 072             1.00    1.05    1.11    1.11    1.30
  84.                 085             1.00    1.17    1.24    1.24    1.34
  85.                 Average         1.00    1.21    1.58    1.59    1.68
  86.  
  87.  
  88. 4.2     Individual Benchmarks
  89.  
  90. The individual results show a fair amount of variation, reflecting the variety
  91. in the six members of the CINT92 suite. SPEC recommends that people do not rely
  92. upon the summary metrics, but rather determine which benchmarks match their
  93. interests and to look carefully at those. With that in mind, the following
  94. short descriptions might be helpful in reviewing these results.
  95.  
  96. o       Espresso and Eqntott are both from scientific applications and should
  97.         show the most improvement from compiler optimizations.
  98.  
  99. o       Li, as a Lisp interpreter recursing and backtracking through the
  100.         N-Queens problem, would showcase the procedure calling overhead.
  101.  
  102. o       Compress and SC are much like many UN*X commands.
  103.  
  104. o       GCC represents large system applications.
  105.  
  106. 4.2.1   085.gcc
  107.  
  108. The code in the 085.gcc benchmark is version 1.35 of the Gnu C Compiler. The
  109. benchmark measures the time it takes a system to use this compiler to generate
  110. several executables for the old Sun-3 workstations.
  111.  
  112. The Gnu Compiler is over 50,000 lines of C code (not counting comments,
  113. blank space, etc.), much of which is fairly representative of large system
  114. applications. Because of its size and its behavior, which is typical of large
  115. software projects, this benchmark has been used by many as a predictor for
  116. performance of both kernel and large application behavior.
  117.  
  118. There was a 17% improvement going from none to just Level One optimization.
  119. There was almost 25% improvement going from none to Level Two optimization.
  120. Additionally, the use of archive libraries rather than shared libraries
  121. obtained another 10% improvement. All this in typical system level code, which
  122. is supposed to render optimizers ineffective.
  123.  
  124. 4.2.2   072.sc
  125.  
  126. This is the public domain UN*X spreadsheet program sc(1) run against three dif-
  127. ferent inputs: a mortgage cost calculation, a small budget calculation, and a
  128. SPECmark89 result calculation. The program sc(1) makes great use of the
  129. curses(3) package to do the screen handling and give a Lotus 1-2-3 look. The
  130. benchmark en- forces a common vt220 terminal definition for the curses(3)
  131. handling no matter what the underlying system, so that all systems are doing
  132. the same work.
  133.  
  134. This benchmark was the one in the suite which showed the least improvement, but
  135. then 072.sc is the benchmark which spends a very large fraction of its time in
  136. library routines: 80%. All of that time spent in the libraries is unaffected by
  137. any compiler optimizations. Even with spending only 1/5th of its time in the
  138. code that the compilers can have an effect upon, Level One optimization got a
  139. gain of 5%, and Level Two brought the advantage up over 10%. This implies that
  140. the optimizer made differences of 25 and 50% in the code that it operated upon.
  141.  
  142. However, with all the calls to the library routines, this is the benchmark
  143. which gains the most from using archived instead of shared libraries, almost
  144. 20%. Thus, it is very important that those programs which make a lot of calls
  145. to library routines are linked from the archived libraries rather than from
  146. the shared libraries. Together, even this benchmark, can run 30% faster than
  147. with the defaults.
  148.  
  149. 4.2.3   026.compress
  150.  
  151. The 026.compress benchmark is from a public-domain version of the UN*X
  152. compress(1) utility using the Lempel-Ziv algorithm. This benchmark reads its
  153. standard input, which is a 1 MB file of random text, and writes a compressed
  154. form to the standard output; then the compressed file is fed back through
  155. standard IO to be uncompressed. The code loops through reading in a block of
  156. data, computing its compressed form, and then writing that out. This makes for
  157. a typical UN*X filter, though perhaps with a bit higher ratio of compute to IO.
  158.  
  159. Perhaps owing to the fair bit of computation per IO buffer, this benchmark
  160. gains almost 20% with just Level One optimization. Then, this performance
  161. gain is doubled when Level Two optimization is enabled. Here again, the amount
  162. of computa- tion per buffer, and in particular the looping nature of that
  163. computation, allows the optimizer to work well. Not surprisingly, for a
  164. benchmark which makes comparably few library calls, the difference between
  165. shared and archived libraries was not significant. But again, the total
  166. increase was over 45% better than the default settings.
  167.  
  168. 4.2.4   023.eqntott
  169.  
  170. One of the most analytical of the CINT92 suite, 023.eqntott is based on a tool
  171. from the area of logic design which translates boolean equations into truth
  172. tables. This integer benchmark is probably the most like the classic floating
  173. point benchmarks: lots of activity inside loops, not a lot of unexpected
  174. branches. Therefore, it is the most likely benchmark to highlight the effect
  175. of the optimizer's capabilities.
  176.  
  177. As expected, this benchmark shows considerable improvement even from just Level
  178. One optimization: 38%. Then, like most scientific applications, Level Two opti-
  179. mization has a great effect, in this case it approaches a 3-fold increase in
  180. performance. And again, even after a considerable speed-up, the use of archived
  181. libraries adds a noticeable gain.
  182.  
  183. 4.2.5   022.li
  184.  
  185. This is the benchmark in the CINT92 suite which most exercises the procedure
  186. calling convention, 022.li is a Lisp interpreter running a code which attempts
  187. to solve the 9-Queens problem with a recursive backtracking algorithm.
  188.  
  189. Again, on this benchmark, Level One gains a 25% performance increase. Level
  190. Two optimization doubles this gain for a total of over a 50% increase. Once
  191. again, just using the default settings leaves out a considerable amount of
  192. performance.
  193.  
  194. 4.2.6   008.espresso
  195.  
  196. This benchmark is taken from another logic design application, in this case the
  197. application generates and optimizes Progammable Logic Arrays. This is another
  198. of the more computational benchmarks.
  199.  
  200. In this case, even Level One gets over 25% improvement. And, one more time, the
  201. use of Level Two does better than double the advantage, to almost 60% better
  202. than the basic compilations. On top of that, building archived rather than
  203. with shared libraries gains several more percentage points, to where this
  204. benchmark measures 66% better fully optimized than it measured under default
  205. conditions.
  206.  
  207. 4.3     8.02 Results
  208.  
  209. There were a lot of enhancements made to the HP-UX 9.0 compilers, but even
  210. so with HP-UX 8.0 it was still worth a fair bit to turn on the optimizer. As
  211. detailed in the table, Level One gained over 15% percent, and Level Two gets
  212. that much again for a total possible improvement of over 30%.
  213.  
  214.  
  215.         Table 2: HP-UX 8.02: Relative Speedups of Various Levels of Optimization
  216.  
  217.                 SPECint92       none    +O1     +O2     +O3     +O3archived
  218.                 008             1.00    1.23    1.41    1.41    1.46
  219.                 022             1.00    1.16    1.31    1.31    1.30
  220.                 023             1.00    1.34    1.74    1.73    1.81
  221.                 026             1.00    1.08    1.24    1.24    1.25
  222.                 072             1.00    1.03    1.06    1.06    1.15
  223.                 085             1.00    1.14    1.18    1.18    1.23
  224.                 Average         1.00    1.16    1.32    1.32    1.37
  225.  
  226.  
  227. Most importantly, however, are the differences in the compilers between 8.02
  228. and 9.0. Starting in 9.0, the compilers are using long branches exclusively
  229. unless the optimizer is activated. This makes the work of the linker much
  230. easier, resulting in much faster link times.  The effect of this is that code
  231. compiled without optimization will run almost 10% slower under 9.0 than 8.02
  232. without even considering what the kernel and the rest of the system does to
  233. the performance.
  234.  
  235.  
  236.         Table 3: 9.0 versus 8.02: Relative Speeds at Various Levels of Optimizat
  237. ion
  238.  
  239.                 SPECint92       none    +O1     +O2     +O3     +O3archived
  240.                 008             0.75    0.76    0.84    0.84    0.85
  241.                 022             0.89    0.96    1.04    1.05    1.07
  242.                 023             0.82    0.84    1.24    1.24    1.26
  243.                 026             0.91    1.00    1.03    1.05    1.07
  244.                 072             1.17    1.19    1.22    1.22    1.32
  245.                 085             0.91    0.94    0.96    0.96    1.00
  246.                 Average         0.91    0.95    1.05    1.06    1.09
  247.  
  248.  
  249. 5.0     Conclusion
  250.  
  251. Compiler optimization technology unlocks the performance potential of the
  252. PA-RISC architecture.  The RISC philosophy has fundamentally changed the role of
  253. the compiler.  As RISC moves to strike a balance between hardware and software
  254. that exploits the best of each technology, the resulting simple, high-perfor-
  255. mance instruction set enables the compiler to apply optimizations that drama-
  256. tically improve performance.  The effectiveness of RISC depends on the compi-
  257. ler's ability to create the optimal instruction sequence by appropriately re-
  258. arranging the program steps.  Without these optimizations, many applications
  259. will execute at a performance level far below their potential.